<template>
	<view class="content">
		<view class="header">专家详情</view>
		<view  class="my-service-title" @click="handleNavBarBack">
			<uv-icon name="arrow-left" size="30rpx" color="#fff"></uv-icon>
		</view>
		<view class="card">
			<view class="img">
				<image :src="expertData[expertId].img" style="width: 100%;" mode="widthFix"></image>
			</view>
			<view class="name">
				{{ expertData[expertId].name }} {{ expertData[expertId].position }}
			</view>
			<view class="company">{{ expertData[expertId].company || '--' }}</view>
			
			<view class="honorList">
				<view class="title">专家简介</view>
				<view class="list" v-for="(item,index) in expertData[expertId].honorList" :key="index">
					{{ item }}
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {onLoad, onShow, onHide } from '@dcloudio/uni-app';
	import { ref } from 'vue';
	import { expertData } from './expertList.js';
	const expertId = ref(0)
	
	// 返回
	const handleNavBarBack = () => {
		uni.navigateBack();
	}
	
	const imgReturn = () => {
		let i = expertId.value + 1;
		return `https://mp-9cd2f666-e017-4f0e-a8b2-2c4583bc29c1.cdn.bspapp.com/expert/图片${i}.png`
	}
	
	const openFun = (item) => {
		if(item.type == 2){
			window.open(item.url)
		}else{
			console.log(item)
			uni.navigateTo({url: item.url})
		}
	}
	
	//分享函数
	const getWin =  async () => { 
		 const currentUrl = 'https://www.yunyakeji.top/';
		
		 // 请求后端获取签名配置
		const res = await vk.callFunction({
			url: 'client/token/pub/index',
			data: { url: currentUrl } // 传递当前URL
		});
		
		const config = res;
		console.log('config',config)
		// 初始化微信SDK
		jWeixin.config({
			debug: false,
			appId: config.appId,
			timestamp: config.timestamp,
			nonceStr: config.noncestr,
			signature: config.signature,
			jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData','onMenuShareAppMessage','onMenuShareTimeline']
		});
		
		jWeixin.ready(() => {
		    // 自定义“分享给朋友”
			 const shareConfig = {
				title: '2025天津市第四届海河肺癌诊疗新进展学术会议',
				desc: '会议日期：6月21日～22日，会议场地：天津梅江中心皇冠假日酒店', // 分享描述
				link: currentUrl, // 使用当前URL
				imgUrl: 'https://mp-9cd2f666-e017-4f0e-a8b2-2c4583bc29c1.cdn.bspapp.com/WechatIMG192.webp', // 分享图标
			};
			
		    jWeixin.updateAppMessageShareData(shareConfig);
		
		    // 自定义“分享到朋友圈”
		    jWeixin.updateTimelineShareData(shareConfig);
			
			// 兼容旧版API
			  jWeixin.onMenuShareAppMessage(shareConfig);
			  
			  jWeixin.onMenuShareTimeline(shareConfig);
		});
		
		jWeixin.error(err => {
			console.error('微信SDK初始化失败', err);
		});
	}
	
	onLoad((query) => {
		expertId.value = query?.expertId ? Number(query?.expertId) : 0; 
		getWin()
	})
</script>

<style lang="scss" scoped>
	.content {
		width: 100vw;
		max-width: 750px;
		height: 100vh;
		background: no-repeat center bottom;
		background-size: auto 100%;
		box-sizing: border-box;
		position: relative;
		display: flex;
		flex-direction: column;
		overflow: hidden;
		margin: 0 auto;
		background-color: #f9fafb;
		

		.header {
			width: 100%;
			height: 112rpx;
			background: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 600;
			font-size: 36rpx;
			color: #111827;
			margin-bottom: 16rpx;
			
		}
		
		.my-service-title {
			width: 54rpx;
			height: 54rpx;
			background: rgba(24, 31, 67, 0.16);
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: fixed;
			top: 30rpx;
			left: 30rpx;
			z-index: 99;
		}
		
		.card{
			width: 100%;
			flex: 1;
			overflow-y: auto;
			padding: 0 32rpx 60rpx;
			box-sizing: border-box;
			
			.img{
				width: 240rpx;
				height: auto;
				margin: 0 auto 32rpx;
				border: 6rpx solid #fff;
				border-radius:40rpx;
				overflow: hidden;
			}
			
			.name{
				width: 100%;
				height: 64rpx;
				font-family: Roboto, Roboto;
				font-weight: 700;
				font-size: 48rpx;
				color: #111827;
				line-height: 64rpx;
				margin: 0 auto 8rpx;
				text-align: center;
			}
			
			.company{
				width: 100;
				height: 42rpx;
				font-family: Roboto, Roboto;
				font-weight: 400;
				font-size: 28rpx;
				color: #6B7280;
				line-height: 42rpx;
				text-align: center;
				margin: 0 auto 56rpx;
			}
			
			.honorList{
				width: 100%;
				height: auto;
				background: #FFFFFF;
				box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(0,0,0,0.05);
				border-radius: 24rpx;
				padding: 32rpx;
				box-sizing: border-box;
				
				.title{
					width: 100%;
					height: 56rpx;
					font-family: Roboto, Roboto;
					font-weight: 700;
					font-size: 36rpx;
					color: #111827;
					line-height: 56rpx;
					margin-bottom: 20rpx;
				}
				
				.list{
					width: 100%;
					height: auto;
					border-bottom: 1px solid #F3F4F6;
					background-color: #fff;
					box-sizing: border-box;
					padding: 20rpx 0;
					font-family: Roboto, Roboto;
					font-weight: 500;
					font-size: 28rpx;
					color: #111827;
					line-height: 42rpx;
					
					&:last-child{
						border: none;
						padding-bottom: 10rpx;
					}
				}
			}
		}
	}
</style>